#include "custombutton.h"
#include <QPainter>
#include <QDebug>
CustomButton::CustomButton(QWidget *p) : QPushButton(p)
{
    resize(100,100);
}

void CustomButton::mousePressEvent(QMouseEvent *e)
{
    co = Qt::green;
    update();
    emit clicked();
}

void CustomButton::mouseReleaseEvent(QMouseEvent *e)
{
    co = Qt::red;
    update();
}

void CustomButton::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    QPen pen;
    pen.setColor(co); //品红
    pen.setWidth(1);
    QBrush brush;
    brush.setColor(co);
    brush.setStyle(Qt::Dense1Pattern);
    painter.setBrush(brush);

    painter.setPen(pen);
    //平移坐标
//    painter.translate(400,400);
    //抗锯齿
//    painter.setRenderHint(QPainter::Antialiasing);

//    painter.drawEllipse(QPoint(50,50),30,30);
    static const QPointF points[3] = {
        QPointF(10.0, 80.0),
        QPointF(20.0, 10.0),
        QPointF(80.0, 30.0)
    };
    painter.drawConvexPolygon(points, 3);
}
